package org.xu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.xu.bo.PicCellBaseBO;
import org.xu.utils.GenerateImageUtil;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/pic/")
@Controller
public class GenerateImageController {

    @RequestMapping("generatePic")
    public void generatePic(HttpServletResponse res){
        PicCellBaseBO cellBaseBO = new PicCellBaseBO();
        cellBaseBO.setDesc("*  资管统计信息,日期: "+ LocalDateTime.now());
        cellBaseBO.setColWidthList(Arrays.asList(280,1200));
        try {
            List<List<String>> dataList = new ArrayList<>();
            dataList.add(Arrays.asList("模块","详情"));
            for (int i = 0; i < 18; i++) {
                List<String> cellData = new ArrayList<>();
                cellData.add("委外三方公司 "+i);
                cellData.add("委外三方公司管理,总数量:37,高逾期委外三方公司总数量:21,低逾期委外三方公司总数量:16");
                dataList.add(cellData);
            }
            BufferedImage image = GenerateImageUtil.generateImage(cellBaseBO,dataList);
            // 保存图片
            ImageIO.write(image, "png", res.getOutputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
